from playwright.sync_api import sync_playwright
import time
import keyboard
import threading


def agree_certificate():
    time.sleep(3)
    keyboard.send("enter")
    print("已点击")


with sync_playwright() as p:
    for browser_type in [p.chromium, p.firefox, p.webkit]:
        browser = browser_type.launch(headless=False)
        #playwright 默认是使用无头模式，所以如果你的headless不作为入参，也是可以让这个
        #脚本执行的，只不过是测试的全程没有启动浏览器
        #有头模式 headless=False
        context = browser.new_context()
        page = context.new_page()

        enter_thread = threading.Thread(target=agree_certificate)
        enter_thread.start()

        page.goto("https://www.q.e0a.cc/")

        enter_thread.join()
        print(page.title())
        page.screenshot(path=f"example-{browser_type.name}.png")
        page.close()
        context.close()
        browser.close()
